package com.example.service;

import com.example.dao.EmployeeMapper;
import com.example.pojo.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;

@Service
public class EmployeeServiceImpe implements EmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;

    //增加一个员工
    @Override
    public void save(Employee employee) {
        employeeMapper.save(employee);
    }

    //查询全部员工信息
    @Override
    public Collection<Employee> getAll() {
        return employeeMapper.getAll();
    }

    //查询员工通过id
    @Override
    public Employee getEmployeeById(Integer id) {
        return employeeMapper.getEmployeeById(id);
    }

    //查询员工通过用户名
    @Override
    public Employee getEmployeeByName(String lastName) {
        return employeeMapper.getEmployeeByName(lastName);
    }

    //删除员工通过id
    @Override
    public void delete(Integer id) {
        //员工存在才删除
        if (employeeMapper.getEmployeeById(id) != null) {
            employeeMapper.delete(id);
        }
    }

    //修改员工信息
    @Override
    public void update(Employee employee) {
        //员工存在才修改
        if (employeeMapper.getEmployeeById(employee.getId()) != null) {
            employeeMapper.update(employee);
        }
    }
}
